<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2018/12/10
 * Time: 15:07
 */
namespace app\admin\controller;

use app\admin\model\RulesModel;
use app\admin\model\GroupModel;
use think\Request;

class Group extends BaseController
{
    //权限组显示页面
    public function index(){
        $GroupModel=new GroupModel();
        $res=$GroupModel->AllData();
        return view('index',['res'=>$res[0],'page'=>$res[1]]);
    }
    //权限组的开启和禁用
    public function isstatus(){
        $GroupModel=new GroupModel();
        $res=$GroupModel->IsStatus(input('id'),input('status'));
        if ($res['code']==1)
            echo "<script>alert('".$res['msg']."')</script>";
        else
            echo "<script>alert('".$res['msg']."')</script>";
        $this->redirect('group/index');
    }
    //权限组的修改页面
    public function update(){
        $id=input('id');
        $GroupModel=new GroupModel();
        $ids=$GroupModel->onerules($id);
        $RulesModel=new RulesModel();
        $rules=$RulesModel->AllDataNF();
        return view('update',['rules'=>$rules,'ids'=>$ids['rulesid'],'name'=>$ids['name'],'id'=>$ids['id']]);
    }
    //权限组的修改操作
    public function updategroup(){
        $id=input('id');
        if(input('rulesid/a'))
            $rules=implode(',',input('rulesid/a'));
        else
            $rules="";
        $name=input('name');
        $GroupModel=new GroupModel();
        $res=$GroupModel->updategroups($id,$rules,$name);
        return $res;
    }
    //权限组的添加页面
    public function change(){
        $RulesModel=new RulesModel();
        $rules=$RulesModel->AllDataNF();
        return view('change',['rules'=>$rules]);
    }
    //权限组的添加操作
    public function add(){
        $title=input('name');
        if(input('rulesid/a'))
            $rules=implode(',',input('rulesid/a'));
        else
            $rules="";
        $GroupModel=new GroupModel();
        $res=$GroupModel->addgroup($title,$rules);
        return $res;
    }
    //删除权限组
    public function del(){
        $GroupModel=new GroupModel();
        $res=$GroupModel->where('id',input('id'))->delete();
        if ($res)
            $this->success('删除成功！','index');
        else
            $this->error('删除失败！');
    }
}